package com.sky.common.config;

import com.sky.common.interceptors.AdminInfoInterceptor;
import com.sky.common.interceptors.UserInfoInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author toki
 */
@Component
@Slf4j
// 利用springboot的自动装配机制，防止被网关扫描
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册 获取用户或员工信息的 自定义拦截器...");
        // 注册获取用户或员工信息的拦截器
        registry.addInterceptor(new UserInfoInterceptor())
                .addPathPatterns("/user/**")
                .addPathPatterns("/notify/**");

        registry.addInterceptor(new AdminInfoInterceptor())
                .addPathPatterns("/admin/**");
    }
}
